# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Link with system-provided openssl library.
pkgname=xh
pkgver=0.16.1
pkgrel=0
pkgdesc="Yet another HTTPie clone"
url="https://github.com/ducaale/xh"
# ppc64le fails to build
# others are blocked by rust/cargo
arch="aarch64 armhf armv7 x86 x86_64"
license="MIT"
checkdepends="curl-dev openssl-dev"
makedepends="cargo oniguruma-dev zlib-dev"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/ducaale/xh/archive/v$pkgver/xh-$pkgver.tar.gz"

export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=1
export CARGO_PROFILE_RELEASE_LTO="true"
export CARGO_PROFILE_RELEASE_OPT_LEVEL="s"
export CARGO_PROFILE_RELEASE_PANIC="abort"

# Link with system-provided oniguruma library (instead building from source
# and bundling).
export RUSTONIG_DYNAMIC_LIBONIG=1

prepare() {
	default_prepare

	cargo fetch --locked
}

build() {
	cargo build --frozen --release
}

check() {
	cargo test --frozen
}

package() {
	install -D -m755 target/release/$pkgname -t "$pkgdir"/usr/bin/

	ln -s xh "$pkgdir"/usr/bin/xhs

	install -Dm 644 doc/xh.1 "$pkgdir"/usr/share/man/man1/xh.1

	install -Dm 644 completions/xh.bash "$pkgdir"/usr/share/bash-completion/completions/xh
	install -Dm 644 completions/xh.fish "$pkgdir"/usr/share/fish/completions/xh.fish
	install -Dm 644 completions/_xh "$pkgdir"/usr/share/zsh/site-functions/_xh
}

sha512sums="
d3514f2436d0371a19a9db8225ed49524b5642a9cd4c643b682b431c1a87a7c1d0413b342e5f242e24638d8ef8694bee3fa1d04d2674ba5ac37b4498b790ff31  xh-0.16.1.tar.gz
"
